package com.emar.adx.yiqifa.java;

import java.io.File;
import java.io.IOException;
import java.net.URL;

/**
 * Created by xiaoliang
 * 2016/8/26 18:31
 *
 * @Version 1.0
 */
public class ClassLoaderMain {

    public void doBootstrapClassLoader(){
        URL[] urls = sun.misc.Launcher.getBootstrapClassPath().getURLs();
        for (int i = 0; i < urls.length; i++) {
            System.out.println(urls[i].toExternalForm());
        }
    }

    public void doLoad() throws IOException{
        //方式一
        System.out.println(System.getProperty("user.dir"));
        //方式二
        File directory = new File("");//设定为当前文件夹
        try{
            System.out.println(directory.getCanonicalPath());//获取标准的路径
            System.out.println(directory.getAbsolutePath());//获取绝对路径
        }catch(Exception e)
        {
            e.printStackTrace();
        }
        //方式三
        System.out.println(ClassLoaderMain.class.getResource("/"));
        System.out.println(ClassLoaderMain.class.getResource(""));
        //方式4
        System.out.println(Object.class.getClassLoader().getResource(""));
        System.out.println(ClassLoaderMain.class.getClassLoader().getResource("logback.xml"));

        System.out.print("ok");
    }

    public static void main(String[] args) {
        ClassLoaderMain main = new ClassLoaderMain();
        try {
            main.doLoad();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
